#pragma once
#include <odb/core.hxx>
#include <odb/nullable.hxx>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <string>
#pragma db object
class User
{
public:
    User() = default;
    User(const std::string &user_id, const std::string &user_name, const std::string &password) 
        : _user_id(user_id) 
        , _user_name(user_name)
        , _password(password)
    {}
    User(const std::string &user_id, const std::string& phone)
        : _user_id(user_id)
        , _user_name(user_id)
        , _phone(phone)
    {}

    std::string user_id() const { return _user_id; }
    std::string user_name() const { 
        if(_user_name) 
            return *_user_name; 
        return std::string(); 
    }
    std::string password() const { 
        if(_password) 
            return *_password; 
        return std::string(); 
    }
    std::string description() const { 
        if(_description) 
            return *_description; 
        return std::string(); 
    }
    std::string phone() const { 
        if(_phone) 
            return *_phone; 
        return std::string(); 
    }
    std::string avatar_id() const { 
        if(_avatar_id) 
            return *_avatar_id; 
        return std::string(); 
    }


    void set_user_name(const std::string &user_name) { _user_name = user_name; }
    void set_password(const std::string &password) { _password = password; }
    void set_description(const std::string &description) { _description = description; }
    void set_phone(const std::string &phone) { _phone = phone; }
    void set_avatar_id(const std::string &avatar_id) { _avatar_id = avatar_id; }
    void set_user_id(const std::string &user_id) { _user_id = user_id; }
private:
    friend class odb::access;
    #pragma db id auto
    unsigned long _id; // 数据库分配的 ID
    #pragma db type("varchar(64)") index unique
    std::string _user_id;
    #pragma db type("varchar(64)") index unique
    odb::nullable<std::string> _user_name;
    #pragma db type("varchar(20)")
    odb::nullable<std::string> _password;
    #pragma db type("varchar(64)")
    odb::nullable<std::string> _description;
    #pragma db type("char(12)") index unique
    odb::nullable<std::string> _phone;
    #pragma db type("varchar(20)") 
    odb::nullable<std::string> _avatar_id;
};